﻿using System;
using System.ComponentModel;
using System.Reflection;
using System.Runtime.InteropServices;
using Teigha.Core;

namespace Teigha.TD
{
	public class OdDbPageController : OdRxObject
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdDbPageController(IntPtr cPtr, bool cMemoryOwn) : base(TD_DbPINVOKE.OdDbPageController_SWIGUpcast(cPtr), cMemoryOwn)
		{
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdDbPageController obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdDbPageController()
		{
			this.Dispose();
		}

		public override void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							TD_DbPINVOKE.delete_OdDbPageController(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
			base.Dispose();
		}

		public OdDbPageController() : this(TD_DbPINVOKE.new_OdDbPageController(), MemoryManager.GetMemoryManager().GetCurrentTransaction() == null)
		{
			MemoryTransaction currentTransaction = MemoryManager.GetMemoryManager().GetCurrentTransaction();
			if (currentTransaction != null)
			{
				currentTransaction.AddObject(new OdDbPageController(this.swigCPtr.Handle, true));
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			this.SwigDirectorConnect();
		}

		public virtual int pagingType()
		{
			int result = TD_DbPINVOKE.OdDbPageController_pagingType(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdStreamBuf read(long key)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbPageController_read(this.swigCPtr, key);
			OdStreamBuf result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdStreamBuf)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdStreamBuf)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdStreamBuf)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual bool write(out uint key, OdStreamBuf pStreamBuf)
		{
			bool result = TD_DbPINVOKE.OdDbPageController_write(this.swigCPtr, out key, OdStreamBuf.getCPtr(pStreamBuf));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual void setDatabase(OdDbDatabase pDb)
		{
			TD_DbPINVOKE.OdDbPageController_setDatabase(this.swigCPtr, OdDbDatabase.getCPtr(pDb));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual OdDbDatabase database()
		{
			OdDbDatabase result = (OdDbDatabase)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbPageController_database(this.swigCPtr), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdResult subPage(OdDbObjectId objectId)
		{
			OdResult result = (OdResult)(this.SwigDerivedClassHasMethod("subPage", OdDbPageController.swigMethodTypes7) ? TD_DbPINVOKE.OdDbPageController_subPageSwigExplicitOdDbPageController(this.swigCPtr, OdDbObjectId.getCPtr(objectId)) : TD_DbPINVOKE.OdDbPageController_subPage(this.swigCPtr, OdDbObjectId.getCPtr(objectId)));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		private void SwigDirectorConnect()
		{
			if (this.SwigDerivedClassHasMethod("queryX", OdDbPageController.swigMethodTypes0))
			{
				this.swigDelegate0 = new OdDbPageController.SwigDelegateOdDbPageController_0(this.SwigDirectorqueryX);
			}
			if (this.SwigDerivedClassHasMethod("isA", OdDbPageController.swigMethodTypes1))
			{
				this.swigDelegate1 = new OdDbPageController.SwigDelegateOdDbPageController_1(this.SwigDirectorisA);
			}
			if (this.SwigDerivedClassHasMethod("pagingType", OdDbPageController.swigMethodTypes2))
			{
				this.swigDelegate2 = new OdDbPageController.SwigDelegateOdDbPageController_2(this.SwigDirectorpagingType);
			}
			if (this.SwigDerivedClassHasMethod("read", OdDbPageController.swigMethodTypes3))
			{
				this.swigDelegate3 = new OdDbPageController.SwigDelegateOdDbPageController_3(this.SwigDirectorread);
			}
			if (this.SwigDerivedClassHasMethod("write", OdDbPageController.swigMethodTypes4))
			{
				this.swigDelegate4 = new OdDbPageController.SwigDelegateOdDbPageController_4(this.SwigDirectorwrite);
			}
			if (this.SwigDerivedClassHasMethod("setDatabase", OdDbPageController.swigMethodTypes5))
			{
				this.swigDelegate5 = new OdDbPageController.SwigDelegateOdDbPageController_5(this.SwigDirectorsetDatabase);
			}
			if (this.SwigDerivedClassHasMethod("database", OdDbPageController.swigMethodTypes6))
			{
				this.swigDelegate6 = new OdDbPageController.SwigDelegateOdDbPageController_6(this.SwigDirectordatabase);
			}
			if (this.SwigDerivedClassHasMethod("subPage", OdDbPageController.swigMethodTypes7))
			{
				this.swigDelegate7 = new OdDbPageController.SwigDelegateOdDbPageController_7(this.SwigDirectorsubPage);
			}
			TD_DbPINVOKE.OdDbPageController_director_connect(this.swigCPtr, this.swigDelegate0, this.swigDelegate1, this.swigDelegate2, this.swigDelegate3, this.swigDelegate4, this.swigDelegate5, this.swigDelegate6, this.swigDelegate7);
		}

		private bool SwigDerivedClassHasMethod(string methodName, Type[] methodTypes)
		{
			MethodInfo method = base.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, methodTypes, null);
			return method.DeclaringType.IsSubclassOf(typeof(OdDbPageController));
		}

		private IntPtr SwigDirectorqueryX(IntPtr pClass)
		{
			return OdRxObject.getCPtr(this.queryX((OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(pClass, false))).Handle;
		}

		private IntPtr SwigDirectorisA()
		{
			return OdRxClass.getCPtr(this.isA()).Handle;
		}

		private int SwigDirectorpagingType()
		{
			return this.pagingType();
		}

		private IntPtr SwigDirectorread(long key)
		{
			return OdStreamBuf.getCPtr(this.read(key)).Handle;
		}

		private bool SwigDirectorwrite(uint key, IntPtr pStreamBuf)
		{
			return this.write(out key, (OdStreamBuf)Teigha.Core.Helpers.odrxCreateObjectInternal(pStreamBuf, false));
		}

		private void SwigDirectorsetDatabase(IntPtr pDb)
		{
			this.setDatabase((OdDbDatabase)Teigha.Core.Helpers.odrxCreateObjectInternal(pDb, false));
		}

		private IntPtr SwigDirectordatabase()
		{
			return OdDbDatabase.getCPtr(this.database()).Handle;
		}

		private int SwigDirectorsubPage(IntPtr objectId)
		{
			return (int)this.subPage(new OdDbObjectId(objectId, false));
		}

		private object locker = new object();

		private HandleRef swigCPtr;

		private OdDbPageController.SwigDelegateOdDbPageController_0 swigDelegate0;

		private OdDbPageController.SwigDelegateOdDbPageController_1 swigDelegate1;

		private OdDbPageController.SwigDelegateOdDbPageController_2 swigDelegate2;

		private OdDbPageController.SwigDelegateOdDbPageController_3 swigDelegate3;

		private OdDbPageController.SwigDelegateOdDbPageController_4 swigDelegate4;

		private OdDbPageController.SwigDelegateOdDbPageController_5 swigDelegate5;

		private OdDbPageController.SwigDelegateOdDbPageController_6 swigDelegate6;

		private OdDbPageController.SwigDelegateOdDbPageController_7 swigDelegate7;

		private static Type[] swigMethodTypes0 = new Type[]
		{
			typeof(OdRxClass)
		};

		private static Type[] swigMethodTypes1 = new Type[0];

		private static Type[] swigMethodTypes2 = new Type[0];

		private static Type[] swigMethodTypes3 = new Type[]
		{
			typeof(long)
		};

		private static Type[] swigMethodTypes4 = new Type[]
		{
			typeof(uint).MakeByRefType(),
			typeof(OdStreamBuf)
		};

		private static Type[] swigMethodTypes5 = new Type[]
		{
			typeof(OdDbDatabase)
		};

		private static Type[] swigMethodTypes6 = new Type[0];

		private static Type[] swigMethodTypes7 = new Type[]
		{
			typeof(OdDbObjectId)
		};

		public delegate IntPtr SwigDelegateOdDbPageController_0(IntPtr pClass);

		public delegate IntPtr SwigDelegateOdDbPageController_1();

		public delegate int SwigDelegateOdDbPageController_2();

		public delegate IntPtr SwigDelegateOdDbPageController_3(long key);

		public delegate bool SwigDelegateOdDbPageController_4(uint key, IntPtr pStreamBuf);

		public delegate void SwigDelegateOdDbPageController_5(IntPtr pDb);

		public delegate IntPtr SwigDelegateOdDbPageController_6();

		public delegate int SwigDelegateOdDbPageController_7(IntPtr objectId);
	}
}
